import { defineStore } from 'pinia'

export const useExhibitionListStore = defineStore('exhibitionList', {
  state: () => ({
    searchForm: {
      chinese_name: '',
      city: '',
      industry: null,
      continent: '',
      country: '',
      exhibition_number: '',
      is_supply_chain: null,  // 新增字段
      is_ccpit: null,       // 新增字段
      location_tags: [],    // 新增地点标签数组
      date_range: {
        from: '',
        to: ''
      }
    },
    pagination: {
        sortBy: 'desc',
        descending: false,
        page: 1,
        rowsPerPage: 10,
        rowsNumber: 0  // 总记录数
    }
  }),
  actions: {
    setSearchForm(form) {
      this.searchForm = { 
        ...form,
        // 确保location_tags被保留，如果form中没有提供的话
        location_tags: form.location_tags || this.searchForm.location_tags || []
      }
    },
    setPagination(pagination) {
      this.pagination = { ...pagination }
    },
    resetState() {
      this.searchForm = {
        chinese_name: '',
        city: '',
        industry: null,
        continent: '',
        country: '',
        exhibition_number: '',
        is_supply_chain: null,  // 新增字段
        is_ccpit: null,       // 新增字段
        location_tags: [],    // 重置地点标签数组
        date_range: {
          from: '',
          to: ''
        }
      }
      this.pagination = {
        sortBy: 'desc',
        descending: false,
        page: 1,
        rowsPerPage: 10,
        rowsNumber: 0  // 总记录数
      }
    }
  }
})
